package jp.tkym.labs.store;

import java.sql.Connection;
import java.sql.SQLException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class DdlTestCase {
	private static Connection connection;
	
	@BeforeClass
	public static void setupClass() throws SQLException, ClassNotFoundException{
		connection = new SqliteConnectionFactory().create(SqliteConnectionTest.class.getResource("test.db"));
	}
	@AfterClass	
	public static void teardownClass() throws SQLException, ClassNotFoundException{
		connection.close();
	}
	
	private TableMeta meta = new TableMeta("person2", new String[]{"id","id2"}, new String[]{"id","id2","name"});
	
	@Test
	public void createTable() throws SQLException{
		new DefaultDDLExecutor(connection).create(meta);
	}
	
	/**
	 * Sqliteはどうやらtruncateが存在しないようです。
	 * @throws SQLException
	 */
	@Test
	public void truncateTable() throws SQLException{
		connection.createStatement().execute("delete from person2");
		if(!connection.getAutoCommit()) connection.commit();
	}
	
	/**
	 * 
	 * @throws SQLException
	 */
	@Test
	public void dropTable() throws SQLException{
		new DefaultDDLExecutor(connection).drop(meta);
	}
}